*Figure 1(b)

*global path "C:\Users\creto\Desktop\chinese_students_2017/"




*load and prepare comtrade data
	insheet using "comtrade.csv", comma clear
	
	collapse (sum) value = tradevalueus, by (year reporter partner tradeflow)
	reshape wide value, i(year reporter partner) j(tradeflow, str)
	reshape wide valueExport valueImport, i(year reporter) j(partner, str)
	renvars *, lower
	renvars value*, postfix(comtrade)


	
*merge together with world bank aggregate trade	

	merge 1:1 year using "tottrade_chn.dta"
	
	rename valueexportusacomtrade exp_usa_ct 
	rename valueimportusacomtrade imp_usa_ct 
	rename valueexportworldcomtrade exp_world_ct 
	rename valueimportworldcomtrade imp_world_ct
	rename exp exp_world_wb 
	rename imp imp_world_wb
	
	*deflate to constant $2010, and express in millions USD
	foreach var of varlist exp_usa_ct imp_usa_ct exp_world_ct imp_world_ct exp_world_wb imp_world_wb {
	
	gen `var'_c2010 = (`var'*usgdp_deflator)/1000000
	
	}
	
	
	
	
* figures
sort year
keep if year>=1980
gr tw (area exp_world_wb_c2010 year, color(gs10) fi(inten50)) (area exp_usa_ct_c2010 year, color(gs0) fi(inten50)), ///
	xlabel(1980(5)2017, labsize(small)) xtitle("") ytitle("Constant 2010 USD (millions)", size(small)) ///
	ylabel(#8, format(%12.0fc) angle(0) labsize(small))	scheme(s1color) ///
	xline(2001, lpatter(dash) lcolor(black)) text(2000000 2001 "China joins WTO {&rarr} ", place(w) size(small)) ///
	legend(label(1 "Exports (Total)") label(2 "Exports (USA)") size(small))
	
*graph export "$path/Figures/fig_trade_trend_bw.eps", replace fontface("Palatino Linotype")
	
	
cap log close
